<template>
	<view>
		<view class="top">
			<view class="search">
				<view class="search-input">
					<text class="yzb yzb-search"></text>
					<input class="text-normal" type="text" :value="searchValue" :placeholder="placeholder" @input="searchInput" />
				</view>
				<view class="btn-cancel" @click="cancelSearch">取消</view>
			</view>
			<yzbfilterDropdown
				:menuTop="0"
				:filterData="filterData"
				:defaultSelected="defaultSelected"
				:updateMenuName="true"
				@confirm="confirm"
				dataFormat="Object"
			></yzbfilterDropdown>
		</view>
		<view class="body">
			<yzb-plan :list="list" @click="toDetail"></yzb-plan>
			<view class="load-more-box">
				<uni-load-more v-if="status == '请求中'" status="正在加载..." :showIcon="true"></uni-load-more>
				<uni-load-more v-if="status == '没有更多'" status="没有更多了" :showIcon="false"></uni-load-more>
				<uni-load-more v-if="status == '暂无数据'" status="暂无数据" :showIcon="false"></uni-load-more>
				<uni-load-more v-if="status == '请求失败'" status="加载失败，点我重试" :showIcon="false" @click="reLoad"></uni-load-more>
			</view>
		</view>
		<!-- <page-tabpars></page-tabpars> -->
	</view>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex';
import yzbfilterDropdown from '@/components/yzb/yzb-filterDropdown.vue';
import mPosition from '@/components/yzb/yzb-position.vue';
import yzbResume from '@/components/yzb/yzb-resume.vue';
export default {
	components: {
		yzbfilterDropdown: yzbfilterDropdown,
		mPosition,
		yzbResume
	},
	computed: {
		...mapState(['userInfo']),
		...mapGetters(['hasLogin'])
	},
	data() {
		return {
			list: [],
			status: '',
			query: {
				page: 1,
				limit: 10,
				planType:'',
				sort:0,//0默认，11-价格升序，10-价格降序，21-经验升序，20-经验降序
			},

			indexArr: '',
			valueArr: '',

			searchValue: '',
			placeholder: '请输入关键词搜索相关内容',
			defaultSelected: [[null],[null]],
			filterData: [
				{
					name: '咨询类型',
					type: 'hierarchy',
					child: []
				},
				{
					name: '排序选择',
					type: 'hierarchy', //filter
					child: [
						{
							name: '默认排序',
							id: '0'
						},
						{
							name: '价格升序',
							id: '11'
						},
						{
							name: '价格降序',
							id: '10'
						},
						{
							name: '经验升序',
							id: '21'
						},
						{
							name: '经验降序',
							id: '20'
						},
					]
				}
			],
			filterData2: [],
			selectPostId: ''
		};
	},
	
	
	onLoad(options) {
		this.initData();
		this.query.page = 1;
		this.getPlanerList();
	},
	onShow() {
	},

	onPullDownRefresh() {
		this.query.page = 1;
		this.getPlanerList();
	},

	onReachBottom() {
		this.query.page++;
		this.getPlanerList();
	},

	methods: {
		
		async initData() {
			let all = {
				name: '全部',
				id: '不限'
			};
			let postList = await this.$apis.getSysCategory({pcode:"B03"});
			console.log("postList=========",postList);
			postList.unshift(all);
			this.filterData[0].child = postList;
		},

		async getPlanerList() {
			this.status = '请求中';
			let res = await this.$apis.getPlanerList(this.query);
			if (res) {
				console.log("getPlanerList=res===",res)
				let data = res.records;
				if(this.query.page==1){
					this.list=[];
				}
				this.list = this.list.concat(data || []);
				this.changeStatus(res);
			}
			uni.stopPullDownRefresh();
		},

		// 修改请求状态
		changeStatus(data) {
			if (this.list.length === 0) {
				this.status = '暂无数据';
			} else if (this.query.page >= Math.ceil(data.total / this.query.limit)) {
				this.status = '没有更多';
			} else {
				this.status = '请求更多';
			}
		},

		toDetail(item) {
			this.$mRouter.push({
				route: this.$mRoutesConfig.planer,
				query: {
					id: item.id
				}
			});
		},

		searchInput(e) {
			this.searchValue = e.detail.value;
			console.log('searchInput', this.searchValue);
			if (this.searchValue) {
				this.query.keyword = this.searchValue;
				this.query.page = 1;
				this.getPlanerList();
			} else {
				this.cancelSearch();
			}
		},
		// 取消搜索
		cancelSearch() {
			this.searchValue = '';
			this.query.keyword = '';
			this.query.page = 1;
			this.getPlanerList();
		},

		confirm(options) {
			console.log('--confirm--', options);
			if (options.value[0][0] != null  && options.value[0][0] != '不限') {
				this.query.planType = options.value[0][0];
			} else {
				this.query.planType = '';
			}
			if (options.value[1][0] != null && options.value[1][0] != '不限') {
				this.query.sort = options.value[1][0];
			} else {
				this.query.sort = '';
			} 
			this.query.page = 1;
			this.list = [];
			this.getPlanerList();
		}
	}
};
</script>
<style lang="scss">
.body {
	margin-top: 170upx;
}

.top {
	width: 100%;
	// height: 180upx;
	position: fixed;
	/* #ifdef H5 */
	top: 44px;
	/* #endif */
	/* #ifndef H5 */
	top: 0;
	/* #endif */
	z-index: 99;
	display: flex;
	flex-direction: column;
}

.search {
	width: 100%;
	display: flex;
	height: 90upx;
	z-index: 999;
	flex-direction: row;
	background-color: $main-color;
	color: #ffffff;
	align-items: center;
	justify-content: center;
	.yzb-search {
		color: $font-color-999;
		font-size: $uni-font-size-base;
		margin: 0 15upx;
		margin-top: 8upx;
	}
	.search-input {
		width: 77%;
		height: 65upx;
		border-radius: 50upx;
		display: flex;
		flex-direction: row;
		background-color: #ffffff;
		align-items: center;
	}
	.search-input image {
		width: 35upx;
		height: 35upx;
		margin-right: 10upx;
	}
	.search-input input {
		width: 65%;
		font-size: 28upx;
		color: $font-color-333;
	}

	.btn-search {
		margin-left: 20upx;
	}

	.btn-cancel {
		margin-left: 20upx;
	}
}
</style>
